hide  display  error - powershell

HI all this is my script :

$list = Get-Content -ErrorAction SilentlyContinue  c:\3.txt$dest =  "C:\Users\%username%\Documents\Outlook Files\" foreach ($line in $list)  {xcopy -ErrorAction SilentlyContinue $line $dest /y  del   $line}


i get some error but everything is working well
ho can i hide the error with "-ErrorAction SilentlyContinue" where i need to put the parameter

February 2nd, 2015 5:01am

Hello Meir,

you are mixing Batch and Powershell Syntax. This example should never throw an error:

# Get list of files to move
$list = Get-Content "c:\3.txt" -ErrorAction 'SilentlyContinue'

# Set the target destination
$dest = "C:\Users\" + $env:UserName + "\Documents\Outlook Files\"

# For each line in the list, do
foreach ($line in $list)
{
	# Move file to destination. The try/catch block is because when copying from older SMB versions 'SilentlyContinue' won't always work as untended.
	try { Move-Item -Path $line -Destination $dest -Force -Confirm:$false -ErrorAction 'Stop' }
	catch { }
}

See the comments for what each step does (and especially the one in the loop - that one is an oddball issue that just is).

Cheers,
Fred

Free Windows Admin Tool Kit Click here and download it now
February 2nd, 2015 8:29am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics